https://tutorialreference.com/batch-scripting/batch-script-tutorial A
Batch Script Tutorial Batch Script is text file containing lines with commands that get executed in sequence by the Microsoft command interpreter (cmd.exe ).What is a Batch Script?
ABatch Script is text file containing lines with commands that get executed in sequence by the Microsoft command interpreter (cmd.exe ).Batch scripts are stored in text files containing lines with commands that get executed in sequence, one after the other.Batch scripts files have the special extension BAT (.bat ) or CMD (.cmd ). This type of file is recognized by the Operating System and executed through an interface (called shell) provided by a system file called thecommand interpreter . Note: Running a batch file is a simple matter of just clicking on it. Batch files can also be run in a command prompt or the Start-Run line. In this case, the full path must be used, unless the file is in the path environment.Features and Uses of Batch Script
Some of the features of Batch Script: It can read user input so that it can process it further. It has control structures such asfor ,if ,while ,switch for better automation and scripting. It supports advanced features such asFunctions andArrays . It supports regular expressions. It can include other programming codes. Some of the common uses of Batch Script are: Setting up servers for different purposes. Automating housekeeping activities such as deleting unwanted files or log files. Automating the deployment of applications from one environment to another. Installing programs on various machines at once.What is the Windows command interpreter?
Thecommand interpreter is a file responsible for handling and processing the command done at the MS-DOS or Windows command line interface. The command interpreter for Windows iscmd.exe . This application is responsible for creating the command window, accepting configuration commands, and accessing built-in commands such as the Dir command. Note: For Windows scripting,cmd.exe is a legacy technology; a modern equivalent isPowerShell , which is based on .NET. PowerShell's capabilities vastly outstrip those of cmd.exeInterpretation of a Command line
Parsing a command line into a sequence of commands is complex. There are four main things to consider:Variable substitution : A command line is scanned for variable specifications, and any found are replaced with the contents of those variables.Quoting : Special characters can be quoted, to remove their special meanings.Syntax : Command lines are developed into a sequence of commands according to a syntax.Redirection : Redirection specifications are applied, and removed from the command line, before an individual command in a sequence is executed.Let's see the environment related to Batch Script.
Batch Script Environment Writing and Executing
The easiest way to create a batch file is to useNotepad (but you can use any other text editor). This is the simplest tool for creation of batch files. Theexecution environment for the batch scripts is thecommand prompt , orcmd.exe , on WWindows systems. You can launchcmd.exe in different ways: Via the run command or search bar in Start menu (easiest way ) Double-click on the cmd file inC:\Windows\System32 Oncecmd.exe is launched, the command prompt will be displayed.Environment Variables
In order to run batch files from the command prompt, you either need to go to the location to where the batch file is stored or alternatively you can enter the file location in the path environment variable. Thus assuming that the batch file is stored in the locationC:\Application\bin , you would need to follow these instructions for the PATH variable inclusion. In Windows, you need to append the StringC:\Application\bin to the end of the system variable PATH.The following table shows some of the frequently used batch commands:
Batch Script Frequently Used Commands
Commmand | Description |
---|---|
This batch command shows the version of MS-DOS you are using. | |
This is a batch command that associates an extension with a file type (FTYPE), displays existing associations, or deletes an association. | |
This batch command helps in making changes to a different directory, or displays the current directory. | |
This batch command clears the screen. | |
This batch command is used for copying files from one location to the other. | |
This batch command deletes files and not directories. | |
This batch command lists the contents of a directory. | |
This batch command help to find the system date. | |
This batch command displays messages, or turns command echoing on or off. | |
This batch command exits the DOS console. | |
This batch command creates a new directory in the current location. | |
This batch command moves files or directories between directories. | |
This batch command displays or sets the path variable. | |
This batch command prompts the user and waits for a line of input to be entered. | |
This batch command can be used to change or reset the cmd.exe prompt. | |
This batch command removes directories, but the directories need to be empty before they can be removed. | |
Renames files and directories. | |
This batch command is used for remarks in batch files, preventing the content of the remark from being executed. | |
This batch command starts a program in new window, or opens a document. | |
This batch command sets or displays the time. | |
This batch command prints the content of a file or files to the output. | |
This batch command displays the volume labels. | |
Displays or sets the attributes of the files in the current directory. | |
This batch command checks the disk for any problems. | |
This batch command provides a list of options to the user. | |
This batch command invokes another instance of command prompt. | |
This batch command compares 2 files based on the file size. | |
This batch command converts a volume from FAT16 or FAT32 file system to NTFS file system. | |
This batch command shows all installed device drivers and their properties. | |
This batch command extracts files from compressed .cab cabinet files. | |
This batch command searches for a string in files or input, outputting matching lines. | |
This batch command formats a disk to use Windows-supported file system such as FAT, FAT32 or NTFS, thereby overwriting the previous content of the disk. | |
This batch command shows the list of Windows-supplied commands. | |
This batch command displays Windows IP Configuration. Shows configuration by connection and the name of that connection. | |
This batch command adds, sets or removes a disk label. | |
This batch command displays the contents of a file or files, one screen at a time. | |
Provides various network services, depending on the command used. | |
This batch command sends ICMP/IP "echo" packets over the network to the designated address. | |
This batch command shuts down a computer, or logs off the current user. | |
This batch command takes the input from a source file and sorts its contents alphabetically, from A to Z or Z to A. It prints the output on the console. | |
This batch command assigns a drive letter to a local folder, displays current assignments, or removes an assignment. | |
This batch command shows configuration of a computer and its operating system. | |
This batch command ends one or more tasks. | |
This batch command lists tasks, including task name and process id (PID). | |
This batch command copies files and directories in a more advanced way. | |
This batch command displays a tree of all subdirectories of the current directory to any level of recursion or depth. | |
This batch command lists the actual differences between two files. | |
This batch command shows and configures the properties of disk partitions. | |
This batch command sets the title displayed in the console window. | |
Displays the list of environment variables on the current system. | |
Error Code | Description |
---|---|
0 | Program successfully completed. |
1 | Incorrect function. Indicates that Action has attempted to execute non-recognized command in Windows command prompt cmd.exe. |
2 | The system cannot find the file specified. Indicates that the file cannot be found in specified location. |
3 | The system cannot find the path specified. Indicates that the specified path cannot be found. |
5 | Access is denied. Indicates that user has no access right to specified resource. |
9009 0x2331 | Program is not recognized as an internal or external command, operable program or batch file. Indicates that command, application name or path has been misspelled when configuring the Action. |
221225495 0xC0000017 -1073741801 | Not enough virtual memory is available. It indicates that Windows has run out of memory. |
3221225786 0xC000013A -1073741510 | The application terminated as a result of a CTRL+C. Indicates that the application has been terminated either by the user's keyboard input CTRL+C or CTRL+Break or closing command prompt window. |
3221225794 0xC0000142 -1073741502 | The application failed to initialize properly. Indicates that the application has been launched on a Desktop to which the current user has no access rights. Another possible cause is that either gdi32.dll or user32.dll has failed to initialize. |
Option | Description |
---|---|
Specifies the remote system to connect to | |
Specifies the user context under which the command should execute. | |
Specifies the password for the given user context. Prompts for input if omitted. | |
Lists all tasks currently using the given exe/dll name. If the module name is not specified all loaded modules are displayed. | |
Displays services hosted in each process. | |
Displays verbose task information. | |
Displays a set of tasks that match a given criteria specified by the filter. | |
Specifies the output format. Valid values: | |
Specifies that the "Column Header" should not show in the output. Valid only for |
Options | Description |
---|---|
Start window Minimized | |
Start window maximized. | |
Use | |
Use | |
Use | |
Use | |
Use | |
Use |
Options | Description |
---|---|
Installs a new copy of Doskey | |
Sets size of command history buffer. | |
Displays all Doskey macros. | |
Displays all Doskey macros for all executables which have Doskey macros. | |
Displays all Doskey macros for the given executable. | |
Displays all commands stored in memory. | |
Specifies that new text you type is inserted in old text. | |
Specifies that new text overwrites old text. | |
Specifies the executable. | |
Specifies a file of macros to install. | |
Specifies a name for a macro you create. | |
Specifies commands you want to record. |
Command | Description |
---|---|
View the current password and logon restrictions for the computer. | |
Displays your current server or workgroup settings. | |
Adds or removes a computer attached to the windows domain controller. | |
This command can be used to view the details of a particular user account, and add/delete/modify a user | |
This command is used to stop and start a particular service. | |
Display network statistics of the workstation or server. | |
Connects or disconnects your computer from a shared resource or displays information about your connections. |
Name | Replacement Value Used |
---|---|
%CD% | The current directory, not ending in a slash character if it is not in the root directory of the current drive |
%TIME% | The system time in HH:MM:SS.mm format. |
%DATE% | The system date in a format specific to localization. |
%RANDOM% | A generated pseudo-random number between 0 and 32767. |
%ERRORLEVEL% | The error level returned by the last executed command, or by the last called batch script. |
%CMDEXTVERSION% | The version number of the Command Processor Extensions currently used by cmd.exe. |
%CMDCMDLINE% | The content of the command line used when the current cmd.exe was started. |
Characters | Expansion Result |
---|---|
$$ | $ character itself |
$A | & symbol AKA ampersand. A convenience, since it is difficult to place a literal & in the value of the PROMPT environment variable using the SET command. |
$B | Vertical bar '|' (pipe symbol) |
$C | Left parenthesis '(' |
$D | Current date |
$E | ESC (ASCII code 27) |
$F | Right parenthesis ')' |
$G | Greater-than symbol '>' |
$H | Backspace (deletes previous character) |
$L | Less-than symbol '<' |
$M | Remote name linked to the current drive if it is a network drive; empty string otherwise. |
$N | Current drive letter |
$P | Current drive letter and full path |
$Q | '=' (equals sign) |
$S | ' ' (space character) |
$T | Current system time |
$V | Windows version number |
$_ | <CR> (carriage return character, aka "enter") |
$+ | As many plus signs (+) as there are items on the pushd directory stack |
Syntax | Expansion Result | Example |
---|---|---|
%~1 | %1 with no enclosing quotation marks | Not provided |
%~f1 | Full path with a drive letter | C:\Windows\System32\notepad.exe |
%~d1 | Drive letter | C: |
%~p1 | Drive-less path with the trailing backslash | \Windows\System32\ |
%~n1 | For a file, the file name without path and extension For a folder, the folder name | notepad |
%~x1 | File name extension including the period | .exe |
%~s1 | Modify of f, n and x to use short name | Not provided |
%~a1 | File attributes | --a------ |
%~t1 | Date and time of last modification of the file | 02.11.2006 11:45 |
%~z1 | File size | 151040 |
%~pn1 | A combination of p and n | \Windows\System32\notepad |
%~dpnx1 | A combination of several letters | C:\Windows\System32\notepad.exe |
%~$PATH:1 | The full path of the first match found in the folders present in the PATH variable, or an empty string in no match. | |
%~n0 | %~n applied to%0: The extensionless name of the batch | tildetest |
%~nx0 | %~nx applied to%0: The name of the batch | tildetest.bat |
%~d0 | %~f applied to%0: The drive letter of the batch | C: |
%~dp0 | %~dp applied to%0: The folder of the batch with trailing backslash | C:\Users\Joe Hoe\ |
Command | Description |
---|---|
ASSOC | Associates an extension with a file type (FTYPE). |
BREAK | Sets or clears extended CTRL+C checking. |
CALL | Calls one batch program from another. |
CD, CHDIR | Displays or sets the current directory. |
CHCP | Displays or sets the active code page number. |
CLS | Clears the screen. |
COLOR | Sets the console foreground and background colors. |
COPY | Copies files. |
DATE | Displays and sets the system date. |
DEL, ERASE | Deletes one or more files. |
DIR | Displays a list of files and subdirectories in a directory. |
ECHO | Displays messages, or turns command echoing on or off. |
ELSE | Performs conditional processing in batch programs when "IF" is not true. |
ENDLOCAL | Ends localization of environment changes in a batch file. |
EXIT | Quits the CMD.EXE program (command interpreter). |
FOR | Runs a specified command for each file in a set of files. |
FTYPE | Sets the file type command. |
IF | Performs conditional processing in batch programs. |
MD, MKDIR | Creates a directory. |
MOVE | Moves a file to a new location |
PATH | Sets or modifies the PATH environment |
PAUSE | Causes the command session to pause for user input. |
POPD | Changes to the drive and directory poped from the directory stack |
PROMPT | Sets or modifies the string displayed when waiting for input. |
PUSHD | Pushes the current directory onto the stack, and changes to the new directory. |
RD / RMDIR | Removes the directory. |
REM | A comment command. Unlike double-colon (::), the command can be executed. |
REN / RENAME | Renames a file or directory |
SET | Sets or displays shell environment variables |
SETLOCAL | Creates a child-environment for the batch file. |
SHIFT | Moves the batch parameters forward. |
START | Starts a program with various options. |
TIME | Displays or sets the system clock |
TITLE | Changes the window title |
TYPE | Prints the content of a file to the console. |
VER | Shows the command processor, operating system versions. |
VERIFY | Verifies that file copy has been done correctly. |
VOL | Shows the label of the current volume. |
/REINSTALL | Installs a new copy of Doskey. |
/LISTSIZE=size | Sets the size of command history buffer. |
/MACROS | Displays all Doskey macros. |
/MACROS:ALL | Displays all Doskey macros for all executables which have Doskey macros. |
/MACROS:exename | Displays all Doskey macros for the given executable. |
/HISTORY | Displays all commands stored in memory. |
/INSERT | Specifies that new text you type is inserted in the old text. |
/OVERSTRIKE | Specifies that new text overwrites old text. |
/EXENAME=exename | Specifies the executable. |
/MACROFILE=filename | Specifies a file of macros to install. |
macroname | Specifies a name for a macro you create. |
text | Specifies commands you want to record. |
UP,DOWN | The up and down arrows recall commands. |
Esc | Clears current command. |
F7 | Displays command history. |
Alt+F7 | Clears command history. |
[chars]F8 | Searches for command beginning with [chars]. |
F9 | Selects a command by number. |
Alt+F10 | Clears macro definitions. |
$T | Command separator. Allows multiple commands in a macro. |
$1-$9 | Batch parameters. Equivalent to %1-%9 in batch programs. |
$* | Symbol replaced by everything following macro name on the command line. |
/BUFSIZE:size | Sets the size of macro and command buffer. | (default:512) |
/ECHO:on|off | Enables/disables echo of macro expansions. | (default:on) |
/FILE:file | Specifies file containing a list of macros. | |
/HISTORY | Displays all commands stored in memory. | |
/INSERT | Inserts new characters into line when typing. | |
/KEYSIZE:size | Sets the size of keyboard type-ahead buffer. | (default:15) |
/LINE:size | Sets the maximum size of line edit buffer. | (default:128) |
/MACROS | Displays all Doskey macros. | |
/OVERSTRIKE | Overwrites new characters onto the line when typing. | (default) |
/REINSTALL | Installs a new copy of Doskey. | |
macroname | Specifies a name for a macro you create. | |
text | Specifies commands you want to assign to the macro. |
UP,DOWN | Arrows recall commands. |
Esc | Clears current command. |
F7 | Displays command history. |
Alt+F7 | Clears command history. |
[chars]F8 | Searches for command beginning with [chars]. |
F9 | Selects a command by number. |
Alt+F10 | Clears macro definitions. |
$T | Command separator: allows multiple commands in a macro. |
$1-$9 | Batch parameters: equivalent to %1-%9 in batch programs. |
$* | Symbol replaced by everything following macro name on the command line. |
win10colors.cmd
was written by Michele Locati:
The text below is stripped of special characters and will not work. You must copy it from here.
C:\Application\bin
, you would need to follow these instructions for the PATH variable inclusion.
S.No | Commands & Description |
---|---|
1 | VER This batch command shows the version of MS-DOS you are using. |
2 | ASSOC This is a batch command that associates an extension with a file type (FTYPE), displays existing associations, or deletes an association. |
3 | CD This batch command helps in making changes to a different directory, or displays the current directory. |
4 | CLS This batch command clears the screen. |
5 | COPY This batch command is used for copying files from one location to the other. |
6 | DEL This batch command deletes files and not directories. |
7 | DIR This batch command lists the contents of a directory. |
8 | DATE This batch command help to find the system date. |
9 | ECHO This batch command displays messages, or turns command echoing on or off. |
10 | EXIT This batch command exits the DOS console. |
11 | MD This batch command creates a new directory in the current location. |
12 | MOVE This batch command moves files or directories between directories. |
13 | PATH This batch command displays or sets the path variable. |
14 | PAUSE This batch command prompts the user and waits for a line of input to be entered. |
15 | PROMPT This batch command can be used to change or reset the cmd.exe prompt. |
16 | RD This batch command removes directories, but the directories need to be empty before they can be removed. |
17 | REN Renames files and directories |
18 | REM This batch command is used for remarks in batch files, preventing the content of the remark from being executed. |
19 | START This batch command starts a program in new window, or opens a document. |
20 | TIME This batch command sets or displays the time. |
21 | TYPE This batch command prints the content of a file or files to the output. |
22 | VOL This batch command displays the volume labels. |
23 | ATTRIB Displays or sets the attributes of the files in the curret directory |
24 | CHKDSK This batch command checks the disk for any problems. |
25 | CHOICE This batch command provides a list of options to the user. |
26 | CMD This batch command invokes another instance of command prompt. |
27 | COMP This batch command compares 2 files based on the file size. |
28 | CONVERT This batch command converts a volume from FAT16 or FAT32 file system to NTFS file system. |
29 | DRIVERQUERY This batch command shows all installed device drivers and their properties. |
30 | EXPAND This batch command extracts files from compressed .cab cabinet files. |
31 | FIND This batch command searches for a string in files or input, outputting matching lines. |
32 | FORMAT This batch command formats a disk to use Windows-supported file system such as FAT, FAT32 or NTFS, thereby overwriting the previous content of the disk. |
33 | HELP This batch command shows the list of Windows-supplied commands. |
34 | IPCONFIG This batch command displays Windows IP Configuration. Shows configuration by connection and the name of that connection. |
35 | LABEL This batch command adds, sets or removes a disk label. |
36 | MORE This batch command displays the contents of a file or files, one screen at a time. |
37 | NET Provides various network services, depending on the command used. |
38 | PING This batch command sends ICMP/IP "echo" packets over the network to the designated address. |
39 | SHUTDOWN This batch command shuts down a computer, or logs off the current user. |
40 | SORT This batch command takes the input from a source file and sorts its contents alphabetically, from A to Z or Z to A. It prints the output on the console. |
41 | SUBST This batch command assigns a drive letter to a local folder, displays current assignments, or removes an assignment. |
42 | SYSTEMINFO This batch command shows configuration of a computer and its operating system. |
43 | TASKKILL This batch command ends one or more tasks. |
44 | TASKLIST This batch command lists tasks, including task name and process id (PID). |
45 | XCOPY This batch command copies files and directories in a more advanced way. |
46 | TREE This batch command displays a tree of all subdirectories of the current directory to any level of recursion or depth. |
47 | FC This batch command lists the actual differences between two files. |
48 | DISKPART This batch command shows and configures the properties of disk partitions. |
49 | TITLE This batch command sets the title displayed in the console window. |
50 | SET Displays the list of environment variables on the current system. |
S.No | Strings & Description |
---|---|
1 | Create String A string can be created in DOS in the following way. |
2 | Empty String Empty String |
3 | String Interpolation String interpolation is a way to construct a new String value from a mix of constants, variables, literals, and expressions by including their values inside a string literal. |
4 | String Concatenation You can use the set operator to concatenate two strings or a string and a character, or two characters. Following is a simple example which shows how to use string concatenation. |
5 | String length In DOS scripting, there is no length function defined for finding the length of a string. There are custom-defined functions which can be used for the same. Following is an example of a custom-defined function for seeing the length of a string. |
6 | toInt A variable which has been set as string using the set variable can be converted to an integer using the /A switch which is using the set variable. The following example shows how this can be accomplished. |
7 | Align Right This used to align text to the right, which is normally used to improve readability of number columns. |
8 | Left String This is used to extract characters from the beginning of a string. |
9 | Mid String This is used to extract a substring via the position of the characters in the string. |
10 | Remove The string substitution feature can also be used to remove a substring from another string. |
11 | Remove Both Ends This is used to remove the first and the last character of a string. |
12 | Remove All Spaces This is used to remove all spaces in a string via substitution. |
13 | Replace a String To replace a substring with another string use the string substitution feature. |
14 | Right String This is used to extract characters from the end of a string. |
S.No | Strings & Description |
---|---|
1 | If Statement The first decision-making statement is the 'if' statement. |
2 | If/else Statement The next decision making statement is the If/else statement. Following is the general form of this statement. |
3 | Nested If Statements Sometimes, there is a requirement to have multiple 'if' statement embedded inside each other. Following is the general form of this statement. |
Operator | Description | Example |
---|---|---|
+ | Addition of two operands | 1 + 2 will give 3 |
- | Subtracts second operand from the first | 2 - 1 will give 1 |
* | Multiplication of both operands | 2 * 2 will give 4 |
/ | Division of the numerator by the denominator | 3 / 2 will give 1.5 |
% | Modulus operator and remainder of after an integer/float division | 3 % 2 will give 1 |
Operator | Description | Example |
---|---|---|
EQU | Tests the equality between two objects | 2 EQU 2 will give true |
NEQ | Tests the difference between two objects | 3 NEQ 2 will give true |
LSS | Checks to see if the left object is less than the right operand | 2 LSS 3 will give true |
LEQ | Checks to see if the left object is less than or equal to the right operand | 2 LEQ 3 will give true |
GTR | Checks to see if the left object is greater than the right operand | 3 GTR 2 will give true |
GEQ | Checks to see if the left object is greater than or equal to the right operand | 3 GEQ 2 will give true |
Operator | Description |
---|---|
AND | This is the logical ※and§ operator |
OR | This is the logical ※or§ operator |
NOT | This is the logical ※not§ operator |
Operator | Description | Example |
---|---|---|
+= | This adds right operand to the left operand and assigns the result to left operand | Set /A a = 5 a += 3 Output will be 8 |
-= | This subtracts the right operand from the left operand and assigns the result to the left operand | Set /A a = 5 a -= 3 Output will be 2 |
*= | This multiplies the right operand with the left operand and assigns the result to the left operand | Set /A a = 5 a *= 3 Output will be 15 |
/= | This divides the left operand with the right operand and assigns the result to the left operand | Set /A a = 6 a/ = 3 Output will be 2 |
%= | This takes modulus using two operands and assigns the result to the left operand | Set /A a = 5 a% = 3 Output will be 2 |
Operator | Description |
---|---|
& | This is the bitwise ※and§ operator |
| | This is the bitwise ※or§ operator |
^ | This is the bitwise ※xor§ or Exclusive or operator |
p | q | p & q | p | q | p ^ q |
---|---|---|---|---|
0 | 0 | 0 | 0 | 0 |
0 | 1 | 0 | 1 | 1 |
1 | 1 | 1 | 1 | 0 |
1 | 0 | 0 | 1 | 1 |
Error Code | Description |
---|---|
0 | Program successfully completed. |
1 | Incorrect function. Indicates that Action has attempted to execute non-recognized command in Windows command prompt cmd.exe. |
2 | The system cannot find the file specified. Indicates that the file cannot be found in specified location. |
3 | The system cannot find the path specified. Indicates that the specified path cannot be found. |
5 | Access is denied. Indicates that user has no access right to specified resource. |
9009 0x2331 | Program is not recognized as an internal or external command, operable program or batch file. Indicates that command, application name or path has been misspelled when configuring the Action. |
221225495 0xC0000017 -1073741801 | Not enough virtual memory is available. It indicates that Windows has run out of memory. |
3221225786 0xC000013A -1073741510 | The application terminated as a result of a CTRL+C. Indicates that the application has been terminated either by the user's keyboard input CTRL+C or CTRL+Break or closing command prompt window. |
3221225794 0xC0000142 -1073741502 | The application failed to initialize properly. Indicates that the application has been launched on a Desktop to which the current user has no access rights. Another possible cause is that either gdi32.dll or user32.dll has failed to initialize. |
S.No | Loops & Description |
---|---|
1 | While Statement Implementation There is no direct while statement available in Batch Script but we can do an implementation of this loop very easily by using the if statement and labels. |
2 | For Statement - List Implementations The "FOR" construct offers looping capabilities for batch files. Following is the common construct of the 'for' statement for working with a list of values. |
3 | Looping through Ranges The 'for' statement also has the ability to move through a range of values. Following is the general form of the statement. |
4 | Classic for Loop Implementation Following is the classic 'for' statement which is available in most programming languages. |
S.No | Loops & Description |
---|---|
1 | Break Statement Implementation The break statement is used to alter the flow of control inside loops within any programming language. The break statement is normally used in looping constructs and is used to cause immediate termination of the innermost enclosing loop. |
S.No | Functions & Description |
---|---|
1 | Calling a Function A function is called in Batch Script by using the call command. |
2 | Functions with Parameters Functions can work with parameters by simply passing them when a call is made to the function. |
3 | Functions with Return Values Functions can work with return values by simply passing variables names |
4 | Local Variables in Functions Local variables in functions can be used to avoid name conflicts and keep variable changes local to the function. |
5 | Recursive Functions The ability to completely encapsulate the body of a function by keeping variable changes local to the function and invisible to the caller. |
6 | File I/O In Batch Script, it is possible to perform the normal file I/O operations that would be expected in any programming language. |
7 | Creating Files The creation of a new file is done with the help of the redirection filter >. This filter can be used to redirect any output to a file. |
8 | Writing to Files Content writing to files is also done with the help of the redirection filter >. This filter can be used to redirect any output to a file. |
9 | Appending to Files Content writing to files is also done with the help of the double redirection filter >>. This filter can be used to append any output to a file. |
10 | Reading from Files Reading of files in a batch script is done via using the FOR loop command to go through each line which is defined in the file that needs to be read. |
11 | Deleting Files For deleting files, Batch Script provides the DEL command. |
12 | Renaming Files For renaming files, Batch Script provides the REN or RENAME command. |
13 | Moving Files For moving files, Batch Script provides the MOVE command. |
14 | Batch Files Pipes The pipe operator (|) takes the output (by default, STDOUT) of one command and directs it into the input (by default, STDIN) of another command. |
15 | Batch Files Inputs When a batch file is run, it gives you the option to pass in command line parameters which can then be read within the program for further processing. |
16 | Using the SHIFT Operator One of the limitations of command line arguments is that it can accept only arguments till %9. Let's take an example of this limitation. |
17 | Folders In Batch Script, it is possible to perform the normal folder based operations that would be expected in any programming language. |
18 | Creating Folders The creation of a folder is done with the assistance of the MD (Make directory) command. |
19 | Listing Folder Contents The listing of folder contents can be done with the dir command. This command allows you to see the available files and directories in the current directory. |
20 | Deleting Folders For deleting folders, Batch Scripting provides the DEL command. |
21 | Renaming Folders For renaming folders, Batch Script provides the REN or RENAME command. |
22 | Moving Folders For moving folders, Batch Script provides the MOVE command. |